package com.pdstudio.weather;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import com.pdstudio.photos.PhotoGalleryActivity;

public class ProductsActivity extends Activity implements OnClickListener {

	private Handler handler = new Handler() {

		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 0: {
			}
				break;
			}
		};
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_products);
		initiaView();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Intent myIntent = new Intent();
			myIntent = new Intent(ProductsActivity.this, MainActivity.class);
			startActivity(myIntent);
			this.finish();
		}
		return super.onKeyDown(keyCode, event);
	}

	private void initiaView() {

		/*
		 * ImageButton
		 * alarmBtn=(ImageButton)findViewById(R.id.alarm_weather_setting);
		 * alarmBtn.setOnClickListener(this);
		 * 
		 * ImageButton
		 * actualtimeRedaPicBtn=(ImageButton)findViewById(R.id.actualtime_redapic
		 * ); actualtimeRedaPicBtn.setOnClickListener(this);
		 */

		GridView gridview = (GridView) findViewById(R.id.Product_GridView);
		ArrayList<HashMap<String, Object>> meumList = new ArrayList<HashMap<String, Object>>();
		// for (int i = 0; i < 10; i++) {
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("Product_ItemImage", R.drawable.actualweather);
		map.put("Product_ItemText", "天气实景");
		meumList.add(map);
		// map = new HashMap<String, Object>();
		// map.put("Product_ItemImage", R.drawable.detailpredict);
		// map.put("Product_ItemText", "精细预报");
		// meumList.add(map);
		map = new HashMap<String, Object>();
		map.put("Product_ItemImage", R.drawable.emergenceresponse);
		map.put("Product_ItemText", "应急响应");
		meumList.add(map);
		map = new HashMap<String, Object>();
		map.put("Product_ItemImage", R.drawable.predictsignal);
		map.put("Product_ItemText", "预警信号");
		meumList.add(map);
		// map = new HashMap<String, Object>();
		// map.put("Product_ItemImage", R.drawable.vedioitem);
		// map.put("Product_ItemText", "视频节目");
		// meumList.add(map);
		map = new HashMap<String, Object>();
		map.put("Product_ItemImage", R.drawable.lifeinfo);
		map.put("Product_ItemText", "生活指数");
		meumList.add(map);
		// map = new HashMap<String, Object>();
		// map.put("Product_ItemImage", R.drawable.weatherscientifc);
		// map.put("Product_ItemText", "气象科普");
		// meumList.add(map);
		// map = new HashMap<String, Object>();
		// map.put("Product_ItemImage", R.drawable.weathernews);
		// map.put("Product_ItemText", "气象新闻");
		// meumList.add(map);
		map = new HashMap<String, Object>();
		map.put("Product_ItemImage", R.drawable.sunupdown);
		map.put("Product_ItemText", "日出日落");
		meumList.add(map);
		// map = new HashMap<String, Object>();
		// map.put("Product_ItemImage", R.drawable.chinafestival);
		// map.put("Product_ItemText", "农历节气");
		// meumList.add(map);

		// }
		SimpleAdapter saItem = new SimpleAdapter(this, meumList, // 数据源
				R.layout.activity_products_item, // xml实现
				new String[] { "Product_ItemImage", "Product_ItemText" }, // 对应map的Key
				new int[] { R.id.Product_ItemImage, R.id.Product_ItemText }); // 对应R的Id

		// 添加Item到网格中
		gridview.setAdapter(saItem);
		// 添加点击事件
		gridview.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> arg0, View v, int arg2,
					long arg3) {
				int index = arg2;// id是从0开始的
				// Toast.makeText(getApplicationContext(), "你按下了选项：" + index, 0)
				// .show();
				Intent intent = null;
				switch (index) {
				case 0: {
					// intent = new Intent(ProductsActivity.this,
					// ActualTimeReda.class);
					intent = new Intent(ProductsActivity.this,
							PhotoGalleryActivity.class);
				}
					break;
				case 1: {
					intent = new Intent(ProductsActivity.this,
							EmergencyActivity.class);
					// intent = new Intent(ProductsActivity.this,
					// WeatherVeryClearActivity.class);
					/*
					 * Intent intent=new
					 * Intent(ProductsActivity.this,DayMarkActivity.class);
					 * startActivity(intent);
					 */
				}
					break;
				case 2: {
					// intent = new Intent(ProductsActivity.this,
					// EmergencyActivity.class);
					intent = new Intent(ProductsActivity.this,
							WarningListActivity.class);
				}
					break;
				case 3: {
					// intent = new Intent(ProductsActivity.this,
					// WarningActivity.class);
					intent = new Intent(ProductsActivity.this,
							LiveIndexActivity.class);
				}
					break;
				case 5: {
					// Intent intent=new
					// Intent(ProductsActivity.this,DoCameraActivity.class);
					intent = new Intent(ProductsActivity.this,
							LiveIndexActivity.class);
				}
					break;
				case 4: {
					intent = new Intent(ProductsActivity.this,
							SunActivity.class);
					//暂时用来调试站点列表
//					intent = new Intent(ProductsActivity.this,
//							NewStationListStateActivity.class);
					// intent = new Intent(ProductsActivity.this,
					// VideoMainActivity.class);
					// intent =new
					// Intent(ProductsActivity.this,TestVideoActivity.class);
				}
					break;
				case 6: {
					intent = new Intent(ProductsActivity.this,
							ScienceActivity.class);
				}
					break;
				case 7: {
					intent = new Intent(ProductsActivity.this,
							ScienceActivity.class);
				}
					break;
				case 8: {
					intent = new Intent(ProductsActivity.this,
							SunActivity.class);
				}
					break;
				case 9: {
					intent = new Intent(ProductsActivity.this,
							SunActivity.class);
				}
					break;
				default: {
				}
					break;
				}
				startActivity(intent);
				// Toast用于向用户显示一些帮助/提示

			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.weather_products, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_products) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		/*
		 * case R.id.alarm_weather_setting:{ Intent intent=new
		 * Intent(this,WeatherAlarm.class); startActivity(intent); }break; case
		 * R.id.actualtime_redapic:{ Intent intent=new
		 * Intent(this,ActualTimeReda.class); startActivity(intent); }break;
		 */
		default:
			break;
		}
	}
}
